package com.syf.controller.RJController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syf.domain.store.BsCompanyApply;
import com.syf.domain.store.BsEvaluation;
import com.syf.model.R;
import com.syf.service.BsEvaluationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author syf
 * @create 2022-02-08 9:25
 */
@RestController
@RequestMapping("/evaluation")
@Api(tags = "用户评价")
public class BsEvaluationController {

    @Autowired
    private BsEvaluationService bsEvaluationService;

    /**
     * 用户发表一个评论:
     *      添加一条评论
     *      查询所有该应用的评论 -> 取出所有评分 -> 计算平均值
     *      修改该应用信息
     */
    @PostMapping("/before/addEvaluation")
    @CrossOrigin
    @ApiOperation(value = "用户发表一个评论")
    public R add(@RequestBody @Validated BsEvaluation bsEvaluation){
        boolean save = bsEvaluationService.addEvaluation(bsEvaluation);
        if(save){
            return R.ok("新增成功") ;
        }
        return  R.fail("新增失败") ;
    }


    @PostMapping("/before/evaluationList")
    @CrossOrigin
    @ApiOperation(value = "分页条件查询--用户评价列表【应用code, 评论Type】")
    public R<Page<BsEvaluation>> findByPage(@RequestBody BsEvaluation bsEvaluation){
        Page<BsEvaluation> pageData =  bsEvaluationService.findByPage(bsEvaluation) ;
        return R.ok(pageData) ;
    }



   /* @PostMapping("/updateEvaluation")
    @ApiOperation(value = "修改--用户评价信息")
    public R updateEvaluation(@RequestBody  BsEvaluation bsEvaluation){
        boolean update = bsEvaluationService.updateById(bsEvaluation);
        if(update){
            return R.ok("修改成功") ;
        }
        return  R.fail("修改失败") ;
    }
*/


}
